using IceZero.DataStore;
using IceZero.DataStore.InitDB;
using IceZero.RootNode.Helpers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace IcsZero.Client.WebMvc
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Nhibernate 配置
            NHibernateHelperConfig.ConfigAddInputStream(NHibernateHelper.Configuration, NHibernateHelper.GenMappingXMLs(genFile: true));
            //NHibernateHelper.Configure("home.mysql.hibernate.cfg.xml");
            //NHibernateHelper.Configure("work.mysql.hibernate.cfg.xml");
            NHibernateHelper.Configure("work.mssql.hibernate.cfg.xml");
            //NHibernateHelper.Configure("sqlite3.hibernate.cfg.xml");
            NHibernateHelper.AutoBuildUpdateTable(rebuild: false);
            //NHibernateHelper.BindCurrentSessionContext();
            new UserDomainDBInitializer().Initialize();
            new DbInitializer()
                .Initialize()
                .UpdateV1_0_0_1(); ;

            //配置 Mapper映射
            AutoMapperHelper.Configure();

            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                    webBuilder.UseUrls("http://0.0.0.0:8500", "https://0.0.0.0:8501");
                });
    }
}
